********Table E.1 - Indonesia********

*Load data
cd "$reploc/data/created_data"
use indo_full, clear

*Create primary and full sample indicators
sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

egen coh_prov_clust=group(biryear_impl birprov_impl)

gen primarysample1=0
replace primarysample1=1 if rbuc_garefineddif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  biryear_impl>=1961 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pidlink)

gen eithrisk=0
replace eithrisk=1 if rbucdif!=. 

egen fullsample=total(eithrisk), by(pidlink)

*Normalize
gen assets_ia_use=assets_ia/1000000
gen income_ia_use=income_ia/1000000
gen savingnettotal_ia_use=savingnettotal_ia/1000000


keep woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 rbuc rbuc_garefined ifls panel primarysample evermig income_ia_use assets_ia_use savingnettotal_ia_use eithrisk fullsample

label var woman "Woman"
label var imp_age "Age"
label define iflslab 4 "2007" 5 "2014", modify
label values ifls  iflslab
label define pan 1 "Panel" 0 "Non-panel", modify
label values ifls  iflslab
label values panel pan

count if primarysample==1
count if fullsample==1

cd "$reploc/results"
outreg2 using TableE1_Indonesia.tex if primarysample==1, sum(log) replace label eqkeep(N mean) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use)

outreg2 using TableE1_Indonesia.tex if primarysample==1, sum(log) append label eqkeep(N sd) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use)

outreg2 using TableE1_Indonesia.tex if fullsample==1, sum(log) append label sum eqkeep(N mean) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use)

outreg2 using TableE1_Indonesia.tex if fullsample==1, sum(log) append label sum eqkeep(N sd) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use)

**T-test differences
foreach var of varlist rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use  {
gen `var'ps=`var' if primarysample==1
}

local nams rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia_use assets_ia_use savingnettotal_ia_use
foreach nam in `nams'  {
ttest `nam'==`nam'ps, unpaired unequal
}


